package test07;

public class Bank implements  Runnable{
    private int money = 100000;

    @Override
    public void run() {
        for(int i = 0; i < 10; i++) {
            deposit();
            take();
        }
    }

    public synchronized void deposit() {
        if(this.money > 100) {
            try {
                Thread.sleep(1000);
            } catch (Exception e) {
                e.printStackTrace();
            }
            this.money += 10000;
            System.out.println(Thread.currentThread().getName()+"存钱10000，money=" + this.money);
        }
    }

    public synchronized void take() {
        if(this.money > 0) {
            try {
                Thread.sleep(1000);
            } catch (Exception e) {
                e.printStackTrace();
            }
            this.money -= 1000;
            System.out.println(Thread.currentThread().getName()+"取钱1000，money=" + this.money);
        }
    }
}
